package com.xmg.mgrsite.base;

import com.xmg.p2p.base.domain.UserFile;
import com.xmg.p2p.base.domain.Userinfo;
import com.xmg.p2p.base.query.UserFileQO;
import com.xmg.p2p.base.service.IRealAuthService;
import com.xmg.p2p.base.service.IUserFileService;
import com.xmg.p2p.base.service.IUserinfoService;
import com.xmg.p2p.base.util.JSONResult;
import com.xmg.p2p.business.domain.BidRequest;
import com.xmg.p2p.business.query.BidRequestQO;
import com.xmg.p2p.business.service.IBidRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BidRequestMGRController {
    @Autowired
    private IBidRequestService bidRequestService;
    @Autowired
    private IUserinfoService userinfoService;
    @Autowired
    private IRealAuthService realAuthService;
    @Autowired
    private IUserFileService userFileService;

    @RequestMapping("bidrequest_publishaudit_list")
    public String index(@ModelAttribute("qo") BidRequestQO qo, Model model) {
        model.addAttribute("pageResult", bidRequestService.query(qo));
        return "bidrequest/publish_audit";
    }

    @RequestMapping("bidrequest_publishaudit")
    @ResponseBody
    public JSONResult publishAudit(Long id, String remark, int state) {
        bidRequestService.publishAudit(id, remark, state);
        return new JSONResult();
    }

    @RequestMapping("borrow_info")
    public String borrowInfo(Long id,Model model) {
        BidRequest bidRequest = bidRequestService.selectByKey(id);
        model.addAttribute("bidRequest",bidRequest);
        Userinfo userinfo = userinfoService.get(bidRequest.getCreateUser().getId());
        model.addAttribute("userInfo",userinfo);
        model.addAttribute("audits",bidRequestService.listAuditHistoryByBidRequest(id));
        model.addAttribute("realAuth",realAuthService.get(userinfo.getRealAuthId()));
        UserFileQO qo = new UserFileQO();
        qo.setPageSize(-1);
        qo.setApplierId(userinfo.getId());
        qo.setState(UserFile.STATE_PASS);
        model.addAttribute("userFiles",userFileService.query(qo));
        return "bidrequest/borrow_info";
    }
}
